package com.market.cash.utils.dialog

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.market.cash.CashRootApps
import com.market.cash.R
import com.market.cash.databinding.CashNoticeDialogBinding
import com.market.cash.pro.ProDialog
import com.market.cash.utils.CashRootDensityUtil
import com.market.cash.utils.event.CashRootEventHelper
import com.market.cash.utils.event.CashRootEventType

/**
 * CashRoot
 * @Author wwdeng
 * @CreateTime: 2024/10/28 15:50
 * @Annotation：审核中、放款中 提示dialog
 */
class CashRootNoticeDialog: ProDialog {

    private lateinit var binding: CashNoticeDialogBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    override fun initWindow() {
        val params = window!!.attributes
        params.width = CashRootApps.app.getPhoneWidth() - CashRootDensityUtil.dp2px(54f)
        params.height = WindowManager.LayoutParams.WRAP_CONTENT
        window!!.attributes = params
        window!!.setWindowAnimations(R.style.dialog_scale_anim) //修改动画样式
        window!!.setGravity(Gravity.CENTER)
    }
    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = CashNoticeDialogBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(binding.imgClose)
        setOnClickListener(binding.btnConfirm)
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        dismiss()
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    /**
     * 设置提示图标
     */
    fun setTipsIconResource(resId: Int){
        binding.imgIcon.setImageResource(resId)
    }

    /**
     * 设置提示title
     */
    fun setTipsTitle(title: String){
        binding.textTipsTitle.text = title
    }

    /**
     * 设置提示语
     */
    fun setTips(tips: String){
        binding.textTops.text = tips
    }

    /**
     * 设置按钮文字
     */
    fun setBtnText(text: String){
        binding.btnConfirm.text = text
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        CashRootEventHelper.addCashRootRequestEventAction(CashRootEventType.DIALOG.CASHROOT_DIALOG_LOAN_NOTICE_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        CashRootEventHelper.addCashRootRequestEventAction(CashRootEventType.DIALOG.CASHROOT_DIALOG_LOAN_NOTICE_DISMISS,eventRemark)
    }
}